package com.kotlin.android.api.config

import com.kotlin.android.api.key.ApiKey

/**
 * 环境：App构建环境适配:
 * 包括网络请求host、加密、图片代理、埋点、批量请求、等环境参数的匹配分发。
 * 不限于此！
 *
 * Created on 2020/5/7.
 *
 * @author o.s
 */
class Env private constructor() {

    val aesKey: String
    val imgProxyUrl: String
    val gatewayUrl: String
    val batchUrl: String
    val logUrl: String

    /**
     * 服务器地址群
     */
    var hostMisc: String
    var hostCinema: String
    var hostUser: String
    var hostTicket: String
    var hostPayment: String
    var hostCard: String
    var hostSnack: String
    var hostCoupon: String
    var hostActivity: String
    var hostMkt: String
    var hostCount: String

    companion object {
        val instance by lazy { Env() }

        fun isRelease(): Boolean {
            return ApiKey.PRD == AppConfig.instance.api || ApiKey.STG == AppConfig.instance.api
        }
    }

    init {
        when (AppConfig.instance.api) {
            ApiKey.PRD -> {
                imgProxyUrl = ApiConfig.IMAGE_PROXY_URL_PRD
                aesKey = ApiConfig.AES_PRD
                gatewayUrl = ApiConfig.GATEWAY_URL_PRD
                batchUrl = ApiConfig.POST_BATCH_URL_PRD
                logUrl = ApiConfig.POST_LOG_URL_PRD
                // host集群
                hostMisc = ApiConfig.HOST_ARRAY_PRD[0]
                hostCinema = ApiConfig.HOST_ARRAY_PRD[1]
                hostUser = ApiConfig.HOST_ARRAY_PRD[2]
                hostTicket = ApiConfig.HOST_ARRAY_PRD[3]
                hostPayment = ApiConfig.HOST_ARRAY_PRD[4]
                hostCard = ApiConfig.HOST_ARRAY_PRD[5]
                hostSnack = ApiConfig.HOST_ARRAY_PRD[6]
                hostCoupon = ApiConfig.HOST_ARRAY_PRD[7]
                hostActivity = ApiConfig.HOST_ARRAY_PRD[8]
                hostMkt = ApiConfig.HOST_ARRAY_PRD[9]
                hostCount = ApiConfig.HOST_ARRAY_PRD[10]
            }
            ApiKey.STG -> {
                imgProxyUrl = ApiConfig.IMAGE_PROXY_URL_STG
                aesKey = ApiConfig.AES_STG
                gatewayUrl = ApiConfig.GATEWAY_URL_STG
                batchUrl = ApiConfig.POST_BATCH_URL_STG
                logUrl = ApiConfig.POST_LOG_URL_STG
                // host集群
                hostMisc = ApiConfig.HOST_ARRAY_STG[0]
                hostCinema = ApiConfig.HOST_ARRAY_STG[1]
                hostUser = ApiConfig.HOST_ARRAY_STG[2]
                hostTicket = ApiConfig.HOST_ARRAY_STG[3]
                hostPayment = ApiConfig.HOST_ARRAY_STG[4]
                hostCard = ApiConfig.HOST_ARRAY_STG[5]
                hostSnack = ApiConfig.HOST_ARRAY_STG[6]
                hostCoupon = ApiConfig.HOST_ARRAY_STG[7]
                hostActivity = ApiConfig.HOST_ARRAY_STG[8]
                hostMkt = ApiConfig.HOST_ARRAY_STG[9]
                hostCount = ApiConfig.HOST_ARRAY_STG[10]
            }
            else -> {
                imgProxyUrl = ApiConfig.IMAGE_PROXY_URL_QAS
                aesKey = ApiConfig.AES_QAS
                gatewayUrl = ApiConfig.GATEWAY_URL_QAS
                batchUrl = ApiConfig.POST_BATCH_URL_QAS
                logUrl = ApiConfig.POST_LOG_URL_QAS
                // host集群
                hostMisc = ApiConfig.HOST_ARRAY_QAS[0]
                hostCinema = ApiConfig.HOST_ARRAY_QAS[1]
                hostUser = ApiConfig.HOST_ARRAY_QAS[2]
                hostTicket = ApiConfig.HOST_ARRAY_QAS[3]
                hostPayment = ApiConfig.HOST_ARRAY_QAS[4]
                hostCard = ApiConfig.HOST_ARRAY_QAS[5]
                hostSnack = ApiConfig.HOST_ARRAY_QAS[6]
                hostCoupon = ApiConfig.HOST_ARRAY_QAS[7]
                hostActivity = ApiConfig.HOST_ARRAY_QAS[8]
                hostMkt = ApiConfig.HOST_ARRAY_QAS[9]
                hostCount = ApiConfig.HOST_ARRAY_QAS[10]
            }
        }

        initLogDebug()
    }

    private fun initLogDebug() {
//        LogManager.DEBUG = ApiKey.PRD != AppConfig.instance.api
    }
}